package org.akomantoso.core.data;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.akomantoso.core.io.Externalizable;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.util.ParliamentaryAnalysisElementUtil;

/**
 * The complex type parliamentaryAnalysis is a list of all the parliamentary analysis elements that can be used on the
 * analysis of a debate.
 * 
 * <pre>
 *   <xsd:complexType name="parliamentaryAnalysis">
 * 		    <xsd:choice minOccurs="1" maxOccurs="unbounded">
 * 			      <xsd:element ref="quorumVerification"/>
 * 			      <xsd:element ref="voting"/>
 * 			      <xsd:element ref="recount"/>
 * 		    </xsd:choice>
 * 	  </xsd:complexType>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 */
public class ParliamentaryAnalysis implements Externalizable {

	// Mandatory (min 1).
	private final List<ParliamentaryAnalysisElement> _elements = new ArrayList<ParliamentaryAnalysisElement>();

	public List<ParliamentaryAnalysisElement> getElements() {
		return _elements;
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		for (int i = 0, n = _elements.size(); i < n; i++) {
			_elements.get(i).writeExternal(out);
		}
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		ParliamentaryAnalysisElementUtil.read(in, _elements);
	}
	
	
}